this.name			= "bweed-kestrelfalcon-kestrel";
this.author			= "Kaks";
this.copyright		= "Creative Commons: attribution, non-commercial, sharealike.";
this.description	= "Ship's internal systems";
this.version		= "0.9.1";

this.subpleas = {'bweed-kestrel-lengine':'[bweed-engine-plea]','bweed-kestrel-rengine':'[bweed-engine-plea]','bweed-kestrel-lpylon':'[bweed-pylon-plea]','bweed-kestrel-rpylon':'[bweed-pylon-plea]','bweed-kestrel-lwing':'[bweed-wing-plea]','bweed-kestrel-rwing':'[bweed-wing-plea]'}

this.shipSpawned = this.shipWillLaunchFromStation = function()
{
	let e=this.ship.subEntities
	e.items= function()
	{
	for (let i = 0; i < this.length; i++) yield this[i];
	}
	for (let i in e.items())
	{
	//log (i);
	//for (let i in e) if (e[i] && e[i].script){
		i.script.plea = this.subpleas[i.primaryRole];
		i.script.owner = this.ship; //1.70 workaround
		i.script.shipDied = function(){
			//all instances of 'this' inside this function refer to the subentity script
			let str=this.ship.primaryRole;
			//this.owner.call('commsMessage:',this.plea);
			player.commsMessage(expandDescription(this.plea), 5);
			if(str.indexOf('engine')>0)
				//this.owner.call('spawn:', 'explosive_shrapnel '+(Math.round(Math.random()+1)));
				this.owner.spawn('explosive_shrapnel '+(Math.round(Math.random()+1)));
		}
	}
}

this.shipDied = function()
{
/*	this.ship.call('commsMessage:', '[bweed-falcon-plea]');
	this.ship.call('spawn:', 'explosive_shrapnel 6');*/
	this.ship.commsMessage('[bweed-kestrel-plea]', 5);
	this.ship.spawn('explosive_shrapnel', (Math.ceil(Math.random()*4)));
}